<?php

class PollcComponent extends Object{
	
	
	function calcular($poll = null){
		if (!$poll){
			return false;
		}
		$poll['total'] = 0;
		foreach($poll['PollOption'] as $k => $option){
			$poll['total'] += $option['votos'];
		}
		if($poll['total'] != 0){
			foreach($poll['PollOption'] as $k => $option){
				$poll['PollOption'][$k]['porcentaje'] = round(($option['votos'] * 100 )/ $poll['total'],1)."%";
			}	
		}else{
			foreach($poll['PollOption'] as $k => $option){
				$poll['PollOption'][$k]['porcentaje'] = 0;
			}	
		}
		
		return $poll;
	}
	
	
}